package com.pet.web.controller.system;

import com.pet.common.annotation.Log;
import com.pet.common.core.controller.BaseController;
import com.pet.common.core.domain.AjaxResult;
import com.pet.common.core.page.TableDataInfo;
import com.pet.common.enums.BusinessType;
import com.pet.system.domain.PetCustomerUser;
import com.pet.system.service.IPetCustomerUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 客户商家关联Controller
 *
 * @author pet
 * @date 2022-10-15
 */
@Api(value = "客户管理", tags = "客户管理")
@RestController
@RequestMapping("/system/customer")
public class PetCustomerUserController extends BaseController {
    @Autowired
    private IPetCustomerUserService petCustomerUserService;

    /**
     * 查询客户商家关联列表
     */
    @ApiOperation("客户管理列表")
    @PreAuthorize("@ss.hasPermi('system:customer:list')")
    @GetMapping("/list")
    public TableDataInfo list(PetCustomerUser petCustomerUser) {
        startPage();
        List<Map<String, Object>> list = petCustomerUserService.selectPetCustomerCustomerListByUserId(getUserId());
        return getDataTable(list);
    }

    /**
     * 新增客户商家关联
     */
    @PreAuthorize("@ss.hasPermi('system:customer:add')")
    @PostMapping
    public AjaxResult add(@RequestBody PetCustomerUser petCustomerUser) {
        return toAjax(petCustomerUserService.insertPetCustomerUser(petCustomerUser));
    }

    /**
     * 修改客户商家关联
     */
    @PreAuthorize("@ss.hasPermi('system:customer:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody PetCustomerUser petCustomerUser) {
        return toAjax(petCustomerUserService.updatePetCustomerUser(petCustomerUser));
    }

    /**
     * 删除客户商家关联
     */
    @PreAuthorize("@ss.hasPermi('system:customer:remove')")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(petCustomerUserService.deletePetCustomerUserByIds(ids));
    }
}
